#include <bits/stdc++.h>
using namespace std;

int t;
int n,ans;
int a[1000005];

void dfs(int x,int red,int blue,int num)
{
    if(x>n)
    {
        ans=max(ans,num);
        return ;
    }
    int cut=num;
    if(a[x]==a[red])
        cut+=a[red];
    dfs(x+1,x,blue,cut);
    cut=num;
    if(a[x]==a[blue])
        cut+=a[blue];
    dfs(x+1,red,x,cut);
}

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        dfs(2,1,0,0);
        dfs(2,0,1,0);
        cout<<ans<<endl;
        ans=0;
    }
    return 0;
}
